#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=100000;

inline int min(int a, int b) {
  return a<b ? a : b;
}

inline int max(int a, int b) {
  return a>b ? a : b;
}

class SegmentTree;
inline SegmentTree* newSegmentTree(int l, int r);

class SegmentTree {
public:
  int l, r, v;
  SegmentTree *left, *right;

  void set(int t, int tv) {
    if (l==r) {
      v = max(tv, v);
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
	if (!left) {
	  left = newSegmentTree(l, mid);
	}
	left->set(t, tv);
	v = max(v, left->v);
      } else {
	if (!right) {
	  right = newSegmentTree(mid+1, r);
	}
	right->set(t, tv);
	v = max(v, right->v);
      }
    }
  }

  int get(int tl, int tr) {
    if (l==tl && r==tr) {
      return v;
    } else {
      int ret=0, mid=(l+r)/2;
      if (tl<=mid && tr>=l && left) {
	ret = max(ret, left->get(max(tl, l), min(tr, mid)));
      }
      if (tl<=r && tr>mid && right) {
	ret = max(ret, right->get(max(tl, mid+1), min(tr, r)));
      }
      return ret;
    }
  }

  void merge(SegmentTree *o) {
    v = max(v, o->v);
    if (o->left) {
      if (left) {
	left->merge(o->left);
      } else {
	left = o->left;
      }
    }
    if (o->right) {
      if (right) {
	right->merge(o->right);
      } else {
	right = o->right;
      }
    }
  }
};

const int maxsize=10000000;
SegmentTree* newSegmentTree(int l, int r) {
  static SegmentTree sgtpool[maxsize+1];
  static int size=0;
  size++;
  sgtpool[size].l=l, sgtpool[size].r=r, sgtpool[size].v=0;
  sgtpool[size].left=sgtpool[size].right=NULL;
  return sgtpool+size;
}


int main() {
#ifdef DEBUG
  freopen("3338.in", "r", stdin);
  freopen("3338.out", "w", stdout);
#endif

  static int fa[maxn+1], val[maxn+1], ans[maxn+1];
  static bool son[maxn+1];
  static SegmentTree *f[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", fa+i);
    if (fa[i]>0) {
      son[fa[i]] = true;
    }
    f[i] = newSegmentTree(1, n);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", val+i);
  }

  for (int i=n; i>0; i--) {
    ans[i] = f[i]->get(1, val[i])+1;
    f[i]->set(val[i], ans[i]);
    if (fa[i]>0) {
      f[fa[i]]->merge(f[i]);
    }
  }

  for (int i=1; i<=n; i++) {
    printf("%d ", ans[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
